<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
  #triangle{
        width: 0;
        height: 0;
        border: 100px solid;
        border-color: orangered skyblue gold yellowgreen;
    }
  </style>
  <div id="triangle"></div>
  <div id="btn">
    防抖
  </div>
</head>
<body>
  
</body>

<script>
    function send(){
      console.log('我们好棒鸭！');
    }
    const btn = document.getElementById("btn");
    btn.addEventListener("click",debounce(send,1000))
    
    function debounce(send,time){
        let name;
        return function(){
            if(name) clearTimeout(name) //name有值，说明上次定时器还没执行完，这时清除上次定时器
            name = setTimeout(function(){
            send()
        }, time);
    }
}

/**
* s = string
* repeatLimit = 最大重复限度
* repeatLimitString = 根据最大重复限度得出的新String
*/
function getStr(s, repeatLimit) {
  const repeatLimitSting = ''
  if (s === null || s === undefined || s.length <= 0) {
    return
  } 
  for (const key in s) {
    console.log(s[key],repeatLimitSting.push(s[key]));
  }
  return repeatLimitSting
}

getStr('asdasf',3)



</script>
</html>
